package com.caiden_micheal.user.mapper;

import com.caiden_micheal.org.domain.Org;
import com.caiden_micheal.user.domain.PositionOrgUser;
import com.caiden_micheal.user.domain.User;
import com.caiden_micheal.user.domain.UserAuthority;
import com.caiden_micheal.user.vo.RegisterVO;
import com.caiden_micheal.user.vo.UserQueryVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    User findOne(User user);

    void saveUser(RegisterVO registerVO);

    void updateUser(User user);

    void deleteUser(User user);

    List<User> findDesensitizationListPaginationQuery(@Param("user") UserQueryVO user);

    Integer findDesensitizationListQueryCount(@Param("user") UserQueryVO user);

    @Update("UPDATE sys_user SET org_name=#{orgName} WHERE org_id=#{id}")
    void updateOrgName(@Param("orgName") String orgName, @Param("id") Long id);

    @Delete("DELETE FROM sys_user WHERE create_time <= #{dateTime} AND disabled=2")
    void deleteDeActiveUser(@Param("dateTime") String dateTime);

    void updateUserOrgByIds(@Param("userIdList") List<Long> userIdList, @Param("org") Org org);

    List<User> findByPermissionConditionDesensitizationListPaginationQuery(@Param("userAuthorityList") List<UserAuthority> userAuthorityList, @Param("user") UserQueryVO userQueryVO);

    Integer findByPermissionConditionDesensitizationListPaginationQueryCount(@Param("userAuthorityList") List<UserAuthority> userAuthorityList, @Param("user") UserQueryVO userQueryVO);

    List<User> findExcludePermissionConditionDesensitizationListPaginationQuery(@Param("userAuthorityList") List<UserAuthority> userAuthorityList, @Param("user") UserQueryVO userQueryVO);

    Integer findExcludePermissionConditionDesensitizationListPaginationQueryCount(@Param("userAuthorityList") List<UserAuthority> userAuthorityList, @Param("user") UserQueryVO userQueryVO);

    List<User> findUserListByIds(@Param("userIds") List<Long> userIds);

    List<User> findDesensitizationListPaginationQueryByIds(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<PositionOrgUser> positionUserOrgList);

    Integer findDesensitizationListQueryCountByIds(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<PositionOrgUser> positionUserOrgList);

    List<User> findExcludePositionDesensitizationListPaginationQuery(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<PositionOrgUser> positionUserOrgList);

    Integer findExcludePositionDesensitizationListPaginationQueryCount(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<PositionOrgUser> positionUserOrgList);

    List<User> findDesensitizationListByIds(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<Long> userId);

    Integer findCountDesensitizationListByIds(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<Long> userId);

    List<Long> findRepeatUserListByIds(@Param("user") UserQueryVO userQueryVO, @Param("positionList") List<Long> userId);

    void addUser(@Param("user") User user);

    @Select("SELECT * FROM sys_user WHERE username=#{username}")
    User findByUsername(@Param("username") String username);

    @Select("SELECT * FROM sys_user WHERE work_no=#{workNo}")
    User findByWorkNO(@Param("workNo") String workNo);

    void editUser(@Param("user") User user);

    @Select("SELECT id from sys_user WHERE org_id=#{orgId}")
    List<Long> findUserIdsByOrgId(Long orgId);

    @MapKey("username")
    Map<String, Map<String, String>> findMapByUsernameList(@Param("usernameList") List<String> usernameList);
}
